package com.liyuxiang.yygh.user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liyuxiang.yygh.common.result.Result;
import com.liyuxiang.yygh.model.user.UserInfo;
import com.liyuxiang.yygh.user.service.UserInfoService;
import com.liyuxiang.yygh.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable("page") Long page, @PathVariable("limit") Long limit, UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        Page<UserInfo> pageModel = userInfoService.selectPage(pageParam, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    //获取用户详细信息
    @GetMapping("show/{id}")
    public Result getUserDetailsById(@PathVariable("id") Long id) {
        Map<String,Object> paramMap = userInfoService.show(id);
        return Result.ok(paramMap);
    }

    //锁定
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable("userId") Long userId, @PathVariable("status") Long status) {
        boolean flag = userInfoService.lock(userId, status);
        return flag ? Result.ok() : Result.fail();
    }

    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable("userId")Long userId,@PathVariable("authStatus")Integer authStatus){
        boolean flag = userInfoService.approval(userId,authStatus);
        return flag ? Result.ok() : Result.fail();
    }
}
